<?php
/**
 * Created by PhpStorm.
 * User: 何婷婷
 * Date: 2016/11/8
 * Time: 14:28
 */

namespace App\Model;


use App\core\Model;

class LogModel extends Model
{
    static $filename='log.txt';
    public function __construct()
    {
        parent::__construct('user');

    }

    public function setLog($info, $stat = 'INFO')
    {
        file_put_contents(self::$filename, date('Y-m-d/H:m:s', time()) .'|'. 'IP:'.$ip.'|'.$sever_port.'|'. $stat.':' . $info.'\r\n', FILE_APPEND);
    }

    public function getLog()
    {
        return file_get_contents(self::$filename);
    }

    //save() log
    public function getSaveLog(){
        $save=$this->save();
        return $save;
    }

    //get update() log information
    public function getUpdateLog(){
        $update=$this->update();
    }

    //获取localhost
    public  function logInfo()
    {

        $r= 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
        return $r."<br>";
    }

    //获取ip
    public function getIpLog()
    {
        global $ip;

        if (getenv('HTTP_CLIENT_IP')) {  //getenv获取一个环境变量的值。

            $ip = getenv("HTTP_CLIENT_IP");

        } else if (getenv("HTTP_X_FORWARDED_FOR")) {

            $ip = getenv("HTTP_X_FORWARDED_FOR");

        } else if (getenv("REMOTE_ADDR")) {   //getenv("REMOTE_ADDR")用来取得客户端的 IP 地址

            $ip = getenv("REMOTE_ADDR");

        } else if (getenv("HTTP_X_FORWARDED_FOR")) {

            $ip = getenv("HTTP_X_FORWARDED_FOR");

        } else if (getenv("REMOTE_ADDR")) {

            $ip = getenv("REMOTE_ADDR");
        } else {

            $ip = "unknow";
        }
        return $ip;
    }

}

